//
//  PopTransitionAnimation.m
//  UI29-transitionAnimation转场动画
//
//  Created by 韩旭 on 16/8/23.
//  Copyright © 2016年 HX_. All rights reserved.
//

#import "PopTransitionAnimation.h"
#import "ViewController.h"
#import "SecondViewController.h"
@implementation PopTransitionAnimation
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
    return 0.5;
}
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    SecondViewController *secondVc = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    ViewController *view = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    UIView *contaninView = [transitionContext containerView];
    [contaninView addSubview:view.view];
    view.fromImage.hidden = YES;
    UIView *snapView = [view.fromImage snapshotViewAfterScreenUpdates:NO];
    snapView.frame = secondVc.ImageSecond.frame;
    [contaninView addSubview:snapView];
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
        [contaninView layoutIfNeeded];
        snapView.frame = view.fromImage.frame;
    }completion:^(BOOL finished) {
        view.fromImage.hidden = NO;
        [snapView removeFromSuperview];
        [transitionContext completeTransition:YES];
    }];
}


@end
